<template>
	<view class="body">
			<view class="usearch"  @click="onsearch">
				<u-search v-model="content" clearabled="true" borderColor="#ddd"></u-search>
			</view>
			<view class="usearchA"  v-if="listchat">
				<view class="item" v-for="item in title">
					<view class="userava" @click="gomct(item)">
						<u-image :src="item.srcs" shape="circle" height="120rpx" width="120rpx"></u-image>
					</view>
					<view class="fontt" @click="enter(item)">
						<text class="fontsize">{{item.name}}</text>
						
						<view class="textfloat">
							<text class="fonttime">{{item.time}}</text>
						</view>
						<!-- <view class="underfontsize">
							<text class="underfont">{{item.content}}</text>
						</view> -->
					</view>
				</view>
			</view>
		

	</view>
</template>

<script>
	export default{
		data(){
			return{
				content:'',
				listchat:true,
				title:[
					
				],
				openId:'',
			}
		},
		onLoad(){
			//this.title=getApp().globalData.titleChatApp;
		},
		mounted(){
			var _this=this;
			uni.getStorage({
				key:"user",
				success: (res) =>{
					let _this=this;
					_this.openId = res.data.openId
				}
			})
			this.$axios(
			{
				method:'POST',
				url:'/user/getUserList',
			}
			).then(
				res=>{
					const moment = require('moment');
					console.log(res.data);
					var newArr = [];
					for(var i=0; i<res.data.length;i++){
						var tmp={}
						tmp['openId']=res.data[i].openId;
						tmp['name']=res.data[i].userName;
						tmp['srcs']=res.data[i].headImg;
						tmp['email']=res.data[i].email;
						tmp['userIntroduce']=res.data[i].userIntroduce;
						//tmp['content']=res.data[i].userIntroduce;
						tmp['time']=moment(res.data[i].lastLoginTime).format('YYYY-MM-DD HH:mm:ss');
						if(res.data[i].lastLoginTime==null)
							tmp['time']='刚刚';
						//去重
						if(newArr.indexOf(tmp['openId']) == -1){
							newArr.push(tmp['openId']);
							if(_this.openId!=tmp['openId'])
								_this.title.push(tmp);
						}
						console.log(newArr.length);
						
					}
				}
			).catch(
				err=>{
					console.log(err);
				}
			)
		},
		methods:{
			gomct(item){
				uni.navigateTo({
					url:'../merchant/merchant?item='+encodeURIComponent(JSON.stringify(item))
				})
			},
			onsearch(){

				uni.navigateTo({
					url: '../mesSearch/mesSearch'
				})
						
			},
			
			enter:function(item){
				uni.navigateTo({
					url:'../mesChat/mesChat?item='+encodeURIComponent(JSON.stringify(item))
				})
			}
			
			
		}
	}
</script>

<style scoped>
	.usearchA{
		border-top: solid 2px #3b3532;
		/* background-color: #2979FF; */
		margin-top: 20upx;
	}
	.textfloat{
		margin-left: 270upx;
		margin-top: 20upx;
		/* background-color: #2979FF; */
		width: 300upx;
		height: 30upx;
		text-align: right;
	}
	.body{
		font-family:"Hiragino Sans GB","PingFang SC";
		/* background-color: #2979FF;
		height: 1300upx; */
	}
	.userava{
		/* background-color: #000000; */
		height: 120rpx;
		margin-top: 25upx;
		border-radius: 50%;
		border: #a2a2a2;
		border-style: solid;
		border-width: 1upx;
		margin-left: 25upx;
	}
	.usearch{
		margin: 10rpx;
	}
	.item{
		height:170rpx;
		display: flex;
		flex-direction: row;
		border-radius: 20upx;
		background-color: #efefef;
		/* border-top: solid 1px #ddd; */
		/* border-bottom: solid 1px #3cdd55; */
		margin-top: 10rpx;
		box-shadow: 0 1px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
		border: 1upx solid lightgray;
		margin-top: 10upx;
		width: 98%;
		margin-left: 1%;
	}
	.fontt{
		margin-top: 20rpx;
		margin-left: 10rpx;
		display:flex;
		flex-direction: column;
		/* background-color: #3B3532; */
	}
	.fontsize{
		position: absolute;
		margin-top: 7upx;
		margin-left: 10upx;
		font-size: 33rpx;
		padding: 10upx;
		border-radius: 15upx;
		/* box-shadow: 0 1px 1px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04) */
	}
	.underfontsize{
		position: absolute;
		margin-top: 78rpx;
		margin-left: 10rpx;
	}
	.underfont{
		font-size: 28rpx;
		color: #909193;
		margin-left: 15upx;
	}
	.fonttime{
		left:600rpx;
		margin-top: 18rpx;
		color: #909193;
		text-align: right;
		font-size: 28upx;
		/* background-color: #000000; */
	}
	
</style>
